/*
 * Copyright (C) 2013 Daniel Treffenstädt <daniel@treffenstaedt.de>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#ifndef O_STRING_H
#define O_STRING_H

#include "../OGlobal.h"

#include "OObject.h"
#include "OChar.h"

#include <string>
#include <iostream>

O_START_NAMESPACE

class O_EXPORT String : public Object
{
private:
	std::string		m_str;
	int				m_last;

public:
	String(const String& s);
	String(const char* s);
	String(Char c);
	String(std::string s);
	String();
	String arg(String s);
	String append(String s);
	String append(Char c);

	bool contains(String s);
	bool contains(Char c);
	int occurs(String s);
	int occurs(Char c);

	int pos(String s, bool left2right = true);
	int pos(Char c, bool left2right = true);
	String substring(int start, int length);
	String remove(String s);
	String remove(Char c);
	String remove(int start, int length);
	String replace(String find, String replace);
	String replace(Char find, Char replace);

	void clear();

	int length();

	const char* c_str();

	Char operator[] (int index);
	Char charAt(int index);

	int toInt();
	double toDouble();

	void print();
	static String read();

	static String number(short n);
	static String number(int n);
	static String number(long n);

	bool equals(String s);

	String operator+ (String s);
	String operator+ (Char c);

	void operator+= (String s);
	void operator+= (Char c);

	void operator= (String s);
	void operator= (const char* c);

	bool operator== (String s);

	friend std::ostream& operator<<(std::ostream& s, String d);
	friend std::istream& operator>>(std::istream& s, String& d);
	friend String operator+ (const char* c, String s);
	friend String operator+ (std::string c, String s);
};

O_END_NAMESPACE

#endif // O_STRING_H
